<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="archsw0904.controller.authentication.*"%>
<%@ page import="archsw0904.controller.shopping.order.*"%>
<%@ page import="java.util.ArrayList"%>
<%
	request.setCharacterEncoding(application
			.getInitParameter("PARAMETER_ENCODING"));
%>
<jsp:include page="/partial/process_cache.jsp" />
<jsp:include page="/partial/head_menu.jsp" />
<jsp:useBean id="usercache" scope="session"
	class="session.cache.UserCache" />
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Client Info <%
	if (usercache.getHostingNode() != null) {
%> @ <%=usercache.getHostingNode()%> <%
 	}
 %>
</title>
</head>
<body>
<%
	if (!usercache.isClient()) {
		response
				.sendError(401,
						"You have to be log in as a cliet to use this seervice");
		return;
	}

	Boolean badLogIndata = false;
	System.out.println("Inizio");

	Integer token = usercache.getToken();

	AuthenticationManagerServiceLocator authServiceLocation = new AuthenticationManagerServiceLocator();
	authServiceLocation
			.setAuthenticationManagerPortEndpointAddress(application
					.getInitParameter("AUTHENTICATION_MANAGER_WEB_SERVICE_URI"));
	AuthenticationManager authServicePort = authServiceLocation
			.getAuthenticationManagerPort();
	archsw0904.controller.authentication.ProfileClient pc = authServicePort
			.getClientProfile(token);
%>
<table cellspacing="1" cellpadding="2" style="border-style: solid;"
	border="1">
	<caption><strong>Personal information</strong></caption>
	<tr>
		<td><strong>Name</strong></td>
		<td><%=pc.getName()%></td>
	</tr>
	<tr>
		<td><strong>Surname</strong></td>
		<td><%=pc.getSurname()%></td>
	</tr>
	<tr>
		<td><strong>Login name</strong></td>
		<td><%=pc.getEmail()%></td>
	</tr>
	<tr>
		<td><strong>E-Mail</strong></td>
		<td><%=pc.getEmail()%></td>
	</tr>
	<tr>
		<td><strong>State</strong></td>
		<td><%=(pc.getState().compareTo("") == 0) ? "&lt;empty&gt;"
					: pc.getState()%></td>
	</tr>
	<tr>
		<td><strong>Cap</strong></td>
		<td><%=(pc.getCap().compareTo("") == 0) ? "&lt;empty&gt;"
					: pc.getCap()%></td>
	</tr>
	<tr>
		<td><strong>City</strong></td>
		<td><%=(pc.getCity().compareTo("") == 0) ? "&lt;empty&gt;"
					: pc.getCity()%></td>
	</tr>
	<tr>
		<td><strong>Address</strong></td>
		<td><%=(pc.getAddress().compareTo("") == 0) ? "&lt;empty&gt;"
							: pc.getAddress()%></td>
	</tr>
	<tr>
		<td><strong>Telephone</strong></td>
		<td><%=(pc.getTelephone().compareTo("") == 0) ? "&lt;empty&gt;"
							: pc.getTelephone()%></td>
	</tr>
</table>
<br />
<%
	OrderBeanServiceLocator orderServiceLocator = new OrderBeanServiceLocator();
	orderServiceLocator.setOrderBeanPortEndpointAddress(application
			.getInitParameter("ORDER_WEB_SERVICE_URI"));
	OrderBean order = orderServiceLocator.getOrderBeanPort();
	OrderView[] info = new OrderView[1];

	info = order.getOrderView(token);

	BookInfo[] listBook = new BookInfo[0];

	if (info == null) {
		info = new OrderView[0];
	} else {
		out.println("<h2>Your Orders</h2>");
	}
%>
<%
	for (OrderView or : info) {
%>
<div id="<%=or.getOrderId()%>">
<table border="0" cellpadding="2" cellspacing="2">
	<tr>
		<td>
		<table>
			<tr>
				<td><strong>Order Code</strong></td>
				<td><%=or.getOrderId()%></td>
			</tr>
			<tr>
				<td><strong>Name</strong></td>
				<td><%=or.getDeliveryName()%></td>
			</tr>
			<tr>
				<td><strong>Surname</strong></td>
				<td><%=or.getDeliverySurname()%></td>
			</tr>
			<tr>
				<td><strong>ddresse</strong></td>
				<td><%=or.getDeliveryAddress()%></td>
			</tr>
			<tr>
				<td><strong>City</strong></td>
				<td><%=or.getDeliveryCity()%></td>
			</tr>
			<tr>
				<td><strong>State</strong></td>
				<td><%=or.getState()%></td>
			</tr>
			<tr>
				<td><strong>Delivery Code</strong></td>
				<td><%=(or.getDeliveryCode() == null) ? "&lt;not-set&gt;"
								: or.getDeliveryCode()%></td>
			</tr>
			<tr>
				<td><strong>Order Status</strong></td>
				<td><%=or.getStatus()%></td>
			</tr>
		</table>
		</td>

		<td>
		<table border="1">
			<tr>
				<th>ISBN</th>
				<th>Title</th>
				<th>Author</th>
				<th>Copies</th>
				<th>PriceForSingleCopies</th>
			</tr>

			<%
				for (BookInfo bi : or.getBookInfoArray()) {
			%>
			<tr>
				<td><%=bi.getIsbn()%></td>
				<td><%=bi.getTitle()%></td>
				<td><%=bi.getAuthor()%></td>
				<td><%=bi.getCopies()%></td>
				<td><%=bi.getPrice()%></td>
			</tr>
			<%
				}
			%>
			<tr>
				<td colspan="5" align="center"><strong>Total</strong> <%=or.getTotalPrice()%></td>
			</tr>
		</table>
		</td>
	</tr>
</table>
</div>
<br />
<%
	}
%>

</body>
</html>